package com.example.zyfypt_525lmj.model;


import android.support.v7.util.SortedList;
import com.example.zyfypt_525lmj.bean.ArticleBean;
import com.example.zyfypt_525lmj.iface.Articleiface;
import com.example.zyfypt_525lmj.iface.Articlelistener;
import com.example.zyfypt_525lmj.service.ArticleService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;



public class ArticleModer implements Articleiface {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    public ArticleModer() {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }

    @Override
    public void getResultList(String mod, int page, String sessionID, final Articlelistener listener) {

        ArticleService articleService =retrofit.create(ArticleService.class);
        Call<List<ArticleBean>> call= articleService.getArticleList(mod,page,sessionID);
        call.enqueue(new Callback<List<ArticleBean>>() {
            @Override
            public void onResponse(Call<List<ArticleBean>> call, Response<List<ArticleBean>> response) {
                if(response.isSuccessful()&&response.body()!=null)
                {
                    listener.onResponse(response.body());
                }
                else
                {
                    listener.onFail("FAIL");
                }
            }


            public void onFailure(Call<List<ArticleBean>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });

    }
}

